__author__ = 'Vlad'

from util.global_options import write_output
from shape import Shape
from util.type import Type
from util.storage import Storage

class Ellipse(Shape):
    def __init__(self, name, **kwargs):
        super(Ellipse, self).__init__(**kwargs)

        self.default.radius = Storage({'x': 0.0 ,'y': 0.0})
        self.set_default_attrs(self.default)

        self.name = name
        self.shape_type = 'Ellipse'

        self._parse_ellipse_config(kwargs)
        self._make_constructor()

    def get_radius(self):
        """Get radius"""
        return self.attrs.radius

    @write_output
    def set_radius(self, x, y):
        """Set radius"""
        self.attrs.radius.x = round(x, 2)
        self.attrs.radius.y = round(y, 2)
        return '%s.setRadius(%s);' %(self.name, Type.format(self.attrs.radius))

    def _parse_ellipse_config(self, kwargs):
        if 'radius' in kwargs:
            if 'x' in kwargs['radius']:
                self.attrs.radius.x = round(kwargs['radius']['x'], 2)
            if 'y' in kwargs['radius']:
                self.attrs.radius.y = round(kwargs['radius']['y'], 2)
        else:
            raise NameError('parameter "radius" is required')
